<template>
  <div>
    <el-table :data="tableData" border v-loading="loading" :header-cell-style="{'text-align':'center'}"
              :cell-style="{'text-align':'center'}">
      <el-table-column prop="id" label="编号" width="85"></el-table-column>
      <el-table-column fixed prop="user_id" label="用户编号" width="85"></el-table-column>
      <!--<el-table-column prop="cars_id" label="购物车编号" width="92"></el-table-column>-->
      <el-table-column prop="nickname" label="昵称" width="120"></el-table-column>
      <el-table-column prop="sex" label="性别" width="85"></el-table-column>
      <el-table-column prop="phone" label="电话" width="120"></el-table-column>
      <el-table-column prop="post" label="邮编" width="85"></el-table-column>
      <el-table-column prop="receive" label="收货人" width="85"></el-table-column>
      <el-table-column prop="address" label="地址" width="250"></el-table-column>
      <el-table-column prop="order_id" label="订单编号" width="85"></el-table-column>
      <el-table-column prop="order_state" label="订单状态" width="85"></el-table-column>
      <el-table-column prop="memo" label="备注" width="85"></el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" @click="edit(scope.row)">修改</el-button>
          <el-popconfirm title="确定清空所有信息吗?" @confirm="clearPersonal(scope.row)">
            <el-button slot="reference" type="info" icon="el-icon-refresh-right">清空</el-button>
          </el-popconfirm>
          <el-popconfirm title="删除后不可恢复，确定删除吗?" @confirm="delPersonal(scope.row)">
            <el-button slot="reference" type="danger" icon="el-icon-delete">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next"
                   :total="total" page-size="6" @current-change="page"
                   style="margin:20px;">
    </el-pagination>
  </div>
</template>

<script>
  const axios = require('axios')
  export default {
    methods: {
      clearPersonal(row) {
        const _this = this
        axios.get('http://localhost:9000/personal/clearById/' + row.id).then(function (resp) {
          _this.$alert('编号<' + row.id + '>信息已清除', '消息', {
            confirmButtonText: '确定',
            callback: action => {
              window.location.reload()
            }
          });
        })
      },
      delPersonal(row) {
        const _this = this
        axios.get('http://localhost:9000/personal/delById/' + row.id).then(function (resp) {
          _this.$alert('删除成功!', '消息', {
            confirmButtonText: '确定',
            callback: action => {
              window.location.reload()
            }
          });
        })
      },
      edit(row) {
        this.$router.push({
          path: '/myUpdate/updatePersonal',
          query: {
            id: row.id
          }
        });
        console.log('要更新的个人中心id是：' + row.id)
        this.$message('修改')
      },
      page(currentPage) {
        //alert(currentPage)  输出分页的信息 测试
        const _this = this
        this.$axios.get('http://localhost:9000/personal/findPage/' + currentPage + '/6').then(function (resp) {
          //console.log(resp)
          _this.tableData = resp.data.content
          _this.pageSize = resp.data.size
          _this.total = resp.data.totalElements
        })
      }
    }, created() {
      const _this = this
      this.$axios.get('http://localhost:9000/personal/findPage/1/6').then(function (resp) {
        //console.log(resp)
        _this.tableData = resp.data.content
        _this.pageSize = resp.data.size
        _this.total = resp.data.totalElements
      })
    },
    data() {
      return {
        pageSize: '1',
        total: null,
        tableData: null,
        loading: false
      }
    }
  }
</script>

<style scoped>

</style>
